package d2_create_runnable;

import java.util.concurrent.Callable;

/**
 * 2024/6/22  实现Callable接口 16:42
 */
public class MyCallable implements Callable<String> {
     private int n;
     public MyCallable(int n) {
        this.n = n;
    }

    //重写call方法
    @Override
    public String call() throws Exception {

        //描述线程的任务,返回线程执行返回的结果
        //需求：求1-n的和返回
        int sum=0;
        for (int i = 0; i <=n ; i++) {
             sum+=i;
        }
        return "线程求出了1-"+n+"的和是："+sum;
    }
}
